cc.Class({
    extends: cc.Component,

    properties: {
        TailGus: cc.Prefab,
    },


    onLoad() {

    },

    init(setting) {
        console.log("FireTruck-init");
        console.log(setting);

        this.node.stopAllActions();

        this.node._carType = "fireTruck";
        this.tailGusPool = new cc.NodePool();

        this.node.active = true;
        this.node.rotation = setting.isRight ? 0 : 180;
        this.node.x = setting.x;
        this.node.y = setting.y;

        let circleTime = 6;
        if (setting.speedRate) circleTime /= setting.speedRate;
        this.node.runAction(cc.repeatForever(
            cc.rotateBy(circleTime, (setting.isRight ? -1 : 1) * 360)));

        // this.makeTailGus();
    },

    makeTailGus() {
        if (this.hadMakeTail) return;
        this.hadMakeTail = true;
        let self = this;

        clearTimeout(self.makeTailGusTimeout);
        let f = 0;
        (function lambda() {
            if (self.node.parent.active) {
                // console.log("FireTruck-makeTailGus");
                if (f < 5) {
                    let tailGus;
                    if (self.tailGusPool.size() > 0) {
                        tailGus = self.tailGusPool.get();
                    } else {
                        tailGus = cc.instantiate(self.TailGus);
                    }
                    tailGus.getComponent("TailGus").init(self.node.getChildByName("truck"), true, new cc.Color(255, 40, 40));
                    self.makeTailGusTimeout = setTimeout(lambda, 200);
                    f++;
                }
            }
        })();
    },

    stop() {
        this.node.stopAllActions();
        this.node.removeFromParent();
    },

    start() {

    },

    // update (dt) {},
});
